home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / comms / other / slrn / slrn_src / macros / posthook.sl < prev    next >
Text File  |  1999-05-14  |  2KB  |  67 lines

  1. % This file illustrates the use of 'post_file_hook', which gets called
  2. % immediately before a message is posted.  In this example, the header
  3. % and body part of the message is separated, and a shell command is run
  4. % on the body part, finally the head and body are re-assembled.
  5.  
  6. define post_file_hook_command (cmd, file)
  7. {
  8.    variable header_file, body_file;
  9.    variable fp, header_fp, body_fp;
  10.    variable line;
  11.    
  12.    if (1 != get_yes_no_cancel (sprintf ("Execute %s on message", cmd)))
  13.      return;
  14.  
  15.    fp = fopen (file, "r");
  16.    if (fp == NULL)
  17.      return;
  18.  
  19.    header_file = file + "-header";
  20.    body_file = file + "-body";
  21.    
  22.    header_fp = fopen (header_file, "w");
  23.    body_fp = fopen (body_file, "w");
  24.    if ((header_fp == NULL) or (body_fp == NULL))
  25.      return;
  26.  
  27.    while (-1 != fgets (&line, fp))
  28.      {
  29.     if (line == "\n")
  30.       break;
  31.     () = fputs (line, header_fp);
  32.      }
  33.    () = fclose (header_fp);
  34.    
  35.    % Now do body
  36.    while (-1 != fgets (&line, fp))
  37.      {
  38.     () = fputs (line, body_fp);
  39.      }
  40.    () = fclose (body_fp);
  41.  
  42.    () = system (sprintf ("%s %s", cmd, body_file));
  43.    
  44.    fp = fopen (file, "w");
  45.    body_fp = fopen (body_file, "r");
  46.    header_fp = fopen (header_file, "r");
  47.    
  48.    while (-1 != fgets (&line, header_fp))
  49.      () = fputs (line, fp);
  50.    () = fputs ("\n", fp);
  51.    
  52.    while (-1 != fgets (&line, body_fp))
  53.      () = fputs (line, fp);
  54.  
  55.    % No need to close files unless we want to check for errors.  When
  56.    % file pointer variables go out of scope, slang will close the file.
  57. }
  58.  
  59.    
  60. define post_file_hook (file)
  61. {
  62.    % Note: the post_file_hook_command function may be called multiple times, 
  63.    % e.g., once to spell-check the article, once to grammar check it, 
  64.    % and so on.
  65.    post_file_hook_command ("ispell -x", file);
  66. }
  67.